As more information is available regarding the impact of carbon emissions on climate change, it is easier to see how our lifestyles impact our carbon footprint. These lifestyle choices range from our commute to what we have for lunch. These choices vary by country, culture, and individual. The carbon footprint of the average consumption by food group has been calculated for at least 130 countries. These calculations are based on food balance sheets and population data available from the Food and Agriculture Organization of the United Nations (FAO). These visualizations intend to compare the dietary sources of CO2 of non-animal based products to animal-based products and the differences in the food production across countries.
initial <- import(here("data", "food_carbon_footprint_data.xlsx")) %>%
clean_names() %>%
as_tibble()
subset <- initial %>%
mutate(ranking = as.numeric(ranking)) %>%
filter(ranking < 7 |country == "all"| country =="Canada"|country =="Japan"
|country == "Germany"|country =="Mexico"|country =="South Korea"|country =="China")
## Warning in mask$eval_all_mutate(quo): NAs introduced by coercion
#line plot work: CO2/person/year produced by country
initial_longer <- subset %>%
select("ranking", "country","total_animal_products", "total_nonanimal_products",
"animal_nonanimal_difference") %>%
pivot_longer(cols = 3:5,
names_to = "product",
values_to = "CO2_person_year")
nadiff <- subset %>%
arrange(desc(animal_nonanimal_difference)) %>%
select("ranking", "country", "animal_nonanimal_difference") %>%
pivot_longer(cols = 3,
names_to = "product",
values_to = "CO2_person_year")
animal <- subset %>%
pivot_longer(cols = 3:9,
names_to = "product",
values_to = "CO2_person_year")
non_animal <- subset %>%
pivot_longer(cols = 11:14,
names_to = "product",
values_to = "CO2_person_year")
#plot1: animal products
#draft
a1 <- animal %>%
ggplot(aes(product, CO2_person_year, group=country)) +
geom_line(aes(color = country))
a1
#plot2: non-animal products
#draft
na1 <- non_animal %>%
ggplot(aes(product, CO2_person_year, group=country)) +
geom_line(aes(color = country))
na1
#plot3: difference between animal and non-animal products
#draft
d1 <- nadiff %>%
ggplot(aes(CO2_person_year, country)) +
geom_col(aes(fill = country))
d1
#plot1: animal products
a2 <- animal %>%
ggplot(aes(product, CO2_person_year, group=country)) +
geom_line(aes(color = country), size = 2) +
gghighlight(country == "all" |country == "USA" | country =="Canada"| country =="Japan",
unhighlighted_params = list(size = 1)) +
scale_color_viridis_d() +
scale_x_discrete(expand = c(0, 0)) +
labs(title = "CO2/person/year for animal products",
subtitle = "",
x = "animal product",
y = "Co2/person/year (in Kg)") +
theme_minimal()
## Warning: Tried to calculate with group_by(), but the calculation failed.
## Falling back to ungrouped filter operation...
## label_key: country
ggplotly(a2, tooltip = c("country","product","CO2_person_year"))
## Warning in geom2trace.default(dots[[1L]][[4L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomLabelRepel() has yet to be implemented in plotly.
## If you'd like to see this geom implemented,
## Please open an issue with your example code at
## https://github.com/ropensci/plotly/issues
## Warning in geom2trace.default(dots[[1L]][[4L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomLabelRepel() has yet to be implemented in plotly.
## If you'd like to see this geom implemented,
## Please open an issue with your example code at
## https://github.com/ropensci/plotly/issues
## Warning in geom2trace.default(dots[[1L]][[4L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomLabelRepel() has yet to be implemented in plotly.
## If you'd like to see this geom implemented,
## Please open an issue with your example code at
## https://github.com/ropensci/plotly/issues
## Warning in geom2trace.default(dots[[1L]][[4L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomLabelRepel() has yet to be implemented in plotly.
## If you'd like to see this geom implemented,
## Please open an issue with your example code at
## https://github.com/ropensci/plotly/issues
#plot2: non-animal products
#final
na2 <- non_animal %>%
ggplot(aes(product, CO2_person_year, group=country)) +
geom_line(aes(color = country), size = 2) +
gghighlight(country == "all" |country == "USA" | country =="Canada"| country =="Japan",
unhighlighted_params = list(size = 1)) +
scale_color_viridis_d() +
scale_x_discrete(expand = c(0, 0)) +
labs(title = "CO2/person/year for non-animal products",
subtitle = "",
x = "non-animal product",
y = "Co2/person/year (in Kg)") +
theme_minimal()
## Warning: Tried to calculate with group_by(), but the calculation failed.
## Falling back to ungrouped filter operation...
## label_key: country
na2
Difference between the CO2 production of animal product and non-animal product, over a year. A low value means that a larger proportion of the population feeds on plant products which have a better carbon emission footprint.
#plot3: difference between animal and non-animal products
#final
d2 <- nadiff %>%
ggplot(aes(CO2_person_year, reorder(country, CO2_person_year))) +
geom_col(aes(fill = country)) +
geom_col(data = filter(nadiff, country == "all" |country == "USA"),
fill = "#C55644") +
scale_fill_viridis_d() +
labs(title = "Animal v. Non-Animal Products difference",
subtitle = "",
x = "Co2/person/year (Kg)",
y = "") +
theme_minimal()
d2 + theme(legend.position = "none")